package de.rosmi.stuff.groovy
import java.text.*

def dir = new File(/C:\temp/)

def fileSizeFormatiert = { file ->
	def sizeByte = file.size()

	switch ("$sizeByte".size()) {
		case 1..3 : return sizeByte+' B';break
		case 4..6 : DecimalFormat df = new DecimalFormat('#.00');return df.format(sizeByte/(1024))+' KB';break
		case 7..9 : DecimalFormat df = new DecimalFormat('#.00');return df.format(sizeByte/(1024*1024))+' MB';break
		case 10..12 :  DecimalFormat df = new DecimalFormat('#.00');return df.format(sizeByte/(1024*1024*1024))+' GB';break
		default: return sizeByte + ' Byte'
	}
}

dir.eachFile {println it.name + " " + fileSizeFormatiert(it) + " (${it.size()})"}
